<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2024/12/24
  Time: 10:24
  To change this template use File | Settings | File Templates.
--%><%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>首页</title>
    <style>
        /* 整体页面布局 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }
        /* 导航栏样式 */
        nav {
            background-color: #333;
            width: 100%;
            max-width: 1800px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 20px;
        }
        nav a {
            color: white;
            text-decoration: none;
            padding: 10px 15px;
            /* 设置导航栏链接之间的距离为 20px */
            margin-right: 20px;
        }
        nav a:hover {
            background-color: #ddd;
            color: black;
        }
        /* 表格容器样式 */
        .table-container {
            background-color: #fff;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 95%;
            max-width: 1800px;
            margin-top: 20px;
        }
        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            font-size: 1.1em;
        }
        /* 斑马条纹表格行 */
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        /* 操作列样式 */
        td button {
            display: inline-block;
            padding: 6px 12px;
            background-color: #007BFF;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        td button:hover {
            background-color: #0056b3;
        }
        /* 不可操作状态的样式 */
        td span.disabled {
            display: inline-block;
            padding: 6px 12px;
            background-color: #555555;
            color: white;
            border-radius: 3px;
            cursor: not-allowed;
        }
        /* 筛选表单样式 */
        .filter-form {
            background-color: #fff;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
            width: 95%;
            max-width: 1800px;
            margin-top: 30px;
        }
        .filter-form label {
            margin-right: 10px;
        }
        .filter-form input[type="text"],.filter-form input[type="date"] {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 3px;
        }
        .filter-form input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .filter-form input[type="submit"]:hover {
            background-color: #45a049;
        }
        /* 通过按钮的样式 */
        .approve-button {
            display: inline-block;
            padding: 8px 16px;
            background-color: #28a745;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .approve-button:hover {
            background-color: #218838;
        }
        /* 不同意按钮的样式 */
        .reject-button {
            display: inline-block;
            padding: 8px 16px;
            background-color: #dc3545;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 3px;
            cursor: pointer;
            height: 37.8px; /* 设置不同意按钮的高度为 37.8px */
        }
        .reject-button:hover {
            background-color: #c82333;
        }
    </style>
    <!-- 或者使用最新的 jQuery 版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-3.7.1.min.js"></script>
    <script>
        function showRejectDialog(reservationId,classroomId) {
            const rejectReason = prompt("请输入不通过的原因：");
            if (rejectReason) {
                $.ajax({
                    type: "POST",
                    url: "/admin/rejectReservation",
                    data: {
                        reservationId: reservationId,
                        rejectReason: rejectReason,
                        classroomId:classroomId
                    },
                    success: function() {
                        // 刷新页面或更新预约信息列表
                        location.reload();
                    },
                    error: function() {
                        alert("请求失败，请稍后重试。");
                    }
                });
            }
        }
    </script>
</head>
<body>
<nav>
    <div>
        <a href="/reservations">首页</a>
        <a href="/classroomManagement">教室管理</a>  <!-- 新增教室管理链接 -->
        <a href="personalCenter">个人中心</a>  <!-- 新增个人中心链接 -->
    </div>
    <div>
        <a href="/">退出登录</a>
    </div>
</nav>
<form class="filter-form" action="${pageContext.request.contextPath}/admin/filterReservations" method="get">
    <div>
        <label for="userName">用户姓名:</label>
        <input type="text" id="userName" name="userName">
    </div>
    <div>
        <label for="classroomName">教室名称:</label>
        <input type="text" id="classroomName" name="classroomName">
    </div>
    <div>
        <label for="startTime">开始时间:</label>
        <input type="date" id="startTime" name="startTime">
    </div>
    <div>
        <label for="endTime">结束时间:</label>
        <input type="date" id="endTime" name="endTime">
    </div>
    <div>
        <label for="status">状态:</label>
        <input type="text" id="status" name="status">
    </div>
    <div>
        <input type="submit" value="筛选">
    </div>
</form>
<div class="table-container">
    <table border="1px">
        <tr>
            <th>用户姓名</th>
            <th>教室名称</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <c:forEach var="reservation" items="${reservationList}">
            <tr>
                <td>${reservation.user.username}</td>
                <td>${reservation.classroom.classroomName}</td>
                <td><fmt:formatDate value="${reservation.startDatetime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td><fmt:formatDate value="${reservation.endDatetime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>${reservation.status}</td>
                <td>
                    <c:if test="${reservation.status == '申请中'}">
                        <a href="/admin/approveReservation?reservationId=${reservation.reservationId}&classroomId=${reservation.classroom.classroomId}" class="approve-button">同意</a>
                        <button onclick="showRejectDialog(${reservation.reservationId},${reservation.classroom.classroomId})" class="reject-button">不同意</button>
                    </c:if>
                    <c:if test="${reservation.status == '已通过' || reservation.status == '不通过'}">
                        <span class="disabled">已处理</span>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员界面</title>
</head>
<body>

</body>
</html>
